<?php echo isset($notify) ? '<div class="alert bg-danger">'.$notify.'</div>' : "" ?>
<?php echo (isset($success) && !empty($success)) ? '<div class="alert bg-success">'.$success.'</div>' : "" ?>
<form class="form-horizontal" role="form" method="post" action="<?=site_url('exportw/search') ?>">  
  <div class="form-group">
    <label for="inputPassword3" class="col-sm-2 control-label">Tìm theo mã (sản phẩm)</label>
    <div class="col-sm-3">
      <input type="text" name="search" class="form-control" id="inputPassword3" placeholder="Nhập mã sản phẩm hay tên sản phẩm để tìm kiếm.." value="<?=isset($search) ? $search : "" ?>">
    </div>
  </div>
  <!-- <div class="form-group">
  	<label for="inputPassword3" class="col-sm-2 control-label">Lọc theo size</label>
  	<div class="col-sm-3">
	  	<select class="form-control">
		  <option>1</option>
		  <option>2</option>
		  <option>3</option>
		  <option>4</option>
		  <option>5</option>
		</select>
	</div>
	<div class="col-sm-3">
		<select class="form-control" name="size" onchange="this.form.submit()">
		  <option value="">--Tất cả--</option>	
		  <option value="xs" <?=(isset($size) && ($size == 'xs')) ? 'selected' : '' ?>>xs</option>
		  <option value="s" <?=(isset($size) && ($size == 's')) ? 'selected' : '' ?>>s</option>
		  <option value="m" <?=(isset($size) && ($size == 'm')) ? 'selected' : '' ?>>m</option>
		  <option value="l" <?=(isset($size) && ($size == 'l')) ? 'selected' : '' ?>>l</option>
		  <option value="xl" <?=(isset($size) && ($size == 'xl')) ? 'selected' : '' ?>>xl</option>
		  <option value="xxl" <?=(isset($size) && ($size == 'xxl')) ? 'selected' : '' ?>>xxl</option>
		  <option value="xxxl" <?=(isset($size) && ($size == 'xxxl')) ? 'selected' : '' ?>>xxxl</option>
		</select>
	</div>
  </div>   --> 
  <p>
  	<a href="<?=site_url('exportw/uploadExportForm') ?>" class="btn btn-primary" role="button">Import phiếu xuất kho</a>
  </p>
</form>

<div class="table-responsive">
	<table class="table table-bordered">
		<thead>
			<tr class="success">
				<td>Sản phẩm</td>								
				<td>Size</td>
				<td>Code</td>
				<td>Màu</td>										
				<td>Kho</td>						
				<td>Ngày tạo</td>		
				<td>Xuất kho</td>						
			</tr>
		</thead>
		<tbody>
		<script type="text/javascript">
	      var wasSubmitted = false;    
	        function checkBeforeSubmit(){
	          if(!wasSubmitted) {
	            wasSubmitted = true;
	            return wasSubmitted;
	          }
	          return false;
	        }    
	    </script>
			<?php	
				$i = 1;			
				foreach ($storageProducts as $key => $info):		
					echo '<form id="form'.$i.'" action="'.site_url('exportw/process/'.$info['id'].'/'.$info['storage']->id).'" onsubmit="return checkBeforeSubmit()">';								
					echo '<tr>
							<td>'.$info['product']->title.'</td>							
							<td>'.$info['product_size']->size.'</td>
							<td>'.$info['product_code'].'</td>
							<td>'.$info['color'].'</td>
							<td>'.$info['storage']->title.'</td>
							<td>'.$info['date_created'].'</td>
							<td><button type="submit" class="btn btn-primary">Xuất kho</button></td>							
						  </tr>';	
					echo '</form>';					  					
					$i++;
				endforeach;
			?>
		</tbody>
	</table>
	<?= !empty($paging_exportproducts) ? "<div class='pull-right'><span>Tổng cộng: $total sản phẩm</span><br>$paging_exportproducts</div>" : "" ?>	
</div>

<br>
<!-- list all codes will export -->
<?php if(isset($exportCodes)): ?> 
<form method="post" action="<?=site_url('exportw/confirm') ?>">
<h2>Danh sách xuất kho</h2>
<div class="table-responsive">
	<table class="table table-bordered">
		<thead>
			<tr class="success">				
				<td>Sản phẩm</td>								
				<td>Size</td>
				<td>Code</td>		
				<td>Màu</td>								
				<td>Kho</td>						
				<td>Ngày tạo</td>									
			</tr>
		</thead>
		<tbody>
			<?php	
				$i = 1;			
				foreach ($exportCodes as $key => $info):										
					echo '<tr>
							<td>'.$info['product_name'].'</td>							
							<td>'.$info['product_size'].'</td>
							<td>'.$info['product_code'].'</td>
							<td>'.$info['color'].'</td>
							<td>'.$info['storage'].'</td>
							<td>'.$info['date_created'].'</td>								
						  </tr>';						  					
					$i++;
				endforeach;
			?>
		</tbody>
	</table>	
</div>
<button type="submit" name="exportConfirmBtn" value="add-all" class="btn btn-primary">Tạo phiếu xuất kho</button>
</form>
<?php endif; ?>